<script setup>
import { ref, reactive, getCurrentInstance, onMounted, watch, render } from "vue"
import { CirclePlus } from '@element-plus/icons-vue';
import {mw_throttle} from '@/utils'

const instance = getCurrentInstance()
const _this = instance.appContext.config.globalProperties //vue3获取当前this
const storage = _this.$utils.storage;
import { globalStore } from "@/store/global";
const globalVue = globalStore();
const isEdit = ref(globalVue.userInfo?.role != 2 || false); 

// 组件中使用，接收传参的
let propsData = defineProps({
  searchForm: Object,
  selectVehicle: {
    type: Array,
    default: []
  },
  selectGender: {
    type: Array,
    default: []
  },
})
// 组件中使用，接收事件的
const emits = defineEmits(['onSearch', 'addPeople']);

const onSubmit = () => {
  function _submit(){
    emits('onSearch')
  }
  mw_throttle(_submit, 1000)
}
const addPeoples = () => {
  function _submit(){
    emits('addPeople')
  }
  mw_throttle(_submit, 1000)
}
</script>

<template>
  <el-form :inline="true" :model="searchForm" class="form_search_table">
    <el-form-item label="Gender">
      <el-select v-model="searchForm.gender" placeholder="Please select" @change="onSubmit" filterable clearable>
        <el-option v-for="item in selectGender" :key="item.id" :label="item.label" :value="item.value" />
      </el-select>
    </el-form-item>
    <el-form-item label="Using Vehicles">
      <el-select v-model="searchForm.ambulanceId" placeholder="Please select" @change="onSubmit" filterable clearable>
        <el-option v-for="item in selectVehicle" :key="item.id" :label="item.label" :value="item.value" />
      </el-select>
    </el-form-item>
    <el-form-item label="Driver Number">
      <el-input v-model="searchForm.number" placeholder="Search for driver number" @keyup.enter="onSubmit" clearable />
    </el-form-item>
    <el-form-item label="Driver Name">
      <el-input v-model="searchForm.name" placeholder="Search for driver name" @keyup.enter="onSubmit" clearable />
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="onSubmit">Query</el-button>
      <div class="event_btn">
        <el-button type="primary" v-if="globalVue.isTourist" :icon="CirclePlus" @click="addPeoples">Add Driver</el-button>
      </div>
    </el-form-item>
  </el-form>
</template>